﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace UdpServerTest.Services
{
    public class UdpTestService
    {
        public UdpClient UdpClient { get; set; }
        public UdpTestService() {
        
        
        }

        public async Task Run()
        {
            UdpClient = new UdpClient(12910);
            while (true)
            {
                var data = await UdpClient.ReceiveAsync();
                Console.WriteLine($"收到IP为{data.RemoteEndPoint.Address} {data.RemoteEndPoint.Port}的数据");
                Console.WriteLine(UTF8Encoding.UTF8.GetString(data.Buffer));
                await UdpClient.SendAsync(data.Buffer, data.RemoteEndPoint);
                await Task.Delay(1000);
            }
        } 

    }
}
